#include "bchaining.hpp"
#include "../utils/utils.hpp"

#include <boost/foreach.hpp>

namespace mashine { namespace inference {

using namespace mashine::kb;

/**
 * param kBase - pointer to knowlege base
 */
BackwardChainingStrategy::BackwardChainingStrategy(KnowledgeBase * kBase) : InferenceStrategy()
{
	this->root = NULL;
	this->kBase = kBase;
	
	factSearcher = new search::FactsSearchVisitor("*");
	// ruleSearcher = new search::RulesSearchVisitor("*");
	// aFactSearcher = new search::AnalogyFactsSearchVisitor("*");
	// aRuleSearcher = new search::AnalogyRulesSearchVisitor("*");
}

BackwardChainingStrategy::~BackwardChainingStrategy()
{
	APP_LOGGER(info) << "BackwardChainingStrategy destructor called";
}

/**
 * backward chaining algorithm
 *
 * param goal - list of goals to inference
 */
std::vector<Literal *> BackwardChainingStrategy::inference(std::vector<Literal *> const & goal)
{
	APP_LOGGER(info) << "Begin inference " << utils::vector_to_string<Literal>(goal);
	
	BOOST_FOREACH(Literal * g, goal) 
	{
		root = new mashine::kb::Literal(*g);
		root->setDenied(!g->isDenied());
	
		unification(root);
	}
	
	APP_LOGGER(info) << "End inference";
}

void BackwardChainingStrategy::unification(mashine::kb::Literal * const & root)
{
	
}

void BackwardChainingStrategy::production(mashine::kb::Literal * const & root)
{

}

}}